package com.xfcy.blog.controller.system;



import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xfcy.blog.annotation.OperationLogger;
import com.xfcy.blog.common.R;
import com.xfcy.blog.dto.DictDTO;
import com.xfcy.blog.service.DictService;
import com.xfcy.blog.valid.AddGroup;
import com.xfcy.blog.valid.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 字典表(Dict)表控制层
 *
 * @author 晓风残月Lx
 * @since 2023-04-09 11:03:05
 */
@RestController
@RequestMapping("system/dict")
@Api(tags = "字典类型管理")
public class DictController {

    @Resource
    private DictService dictService;

    @GetMapping("/list")
    @ApiOperation(value = "字典列表", httpMethod = "GET", response = R.class, notes = "字典列表")
    @SaCheckLogin
    public R list(Integer pageNo, Integer pageSize, String name, Integer isPublish, String ascColumn, String desColumn) {
        return dictService.listDict(pageNo, pageSize, name, isPublish, ascColumn, desColumn);
    }

    @OperationLogger(value = "批量删除字典")
    @DeleteMapping("/deleteBatch")
    @ApiOperation(value = "批量删除字典", httpMethod = "DELETE", response = R.class, notes = "批量删除字典")
    @SaCheckPermission("/system/dict/deleteBatch")
    public R deleteBatch(@RequestBody List<Long> ids) {
        return dictService.deleteBatchDict(ids);
    }

    @OperationLogger(value = "删除字典")
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除字典", httpMethod = "DELETE", response = R.class, notes = "删除字典")
    @SaCheckPermission("/system/dict/delete")
    public R delete(Long id) {
        return dictService.deleteDict(id);
    }

    @OperationLogger(value = "添加字典")
    @PostMapping("/add")
    @ApiOperation(value = "添加字典", httpMethod = "POST", response = R.class, notes = "添加字典")
    @SaCheckPermission("/system/dict/add")
    public R add(@Validated(AddGroup.class) @RequestBody DictDTO dictDTO) {
        return dictService.addDict(dictDTO);
    }

    @OperationLogger(value = "修改字典")
    @PostMapping("/update")
    @ApiOperation(value = "修改字典", httpMethod = "POST", response = R.class, notes = "修改字典")
    @SaCheckPermission("/system/dict/update")
    public R update(@Validated(UpdateGroup.class) @RequestBody DictDTO dictDTO) {
        return dictService.updateDict(dictDTO);
    }

}

